

#include <gtk/gtk.h>
#include "support.h"
#include "dialog.h"
#include "window.h"
#include "page_state.h"
#include "fileops.h"

/*################## Make a modal massege dialog ###################*/
void gsim_message(const gchar *message,GtkMessageType type)
{
	GtkWidget *dialog;
	dialog=gtk_message_dialog_new(GTK_WINDOW(gsim_appwindow),GTK_DIALOG_DESTROY_WITH_PARENT,type,
                                               GTK_BUTTONS_CLOSE,message);
	gtk_dialog_run (GTK_DIALOG (dialog));
	gtk_widget_hide (dialog);
} 


/*################# Attempt to close a unsvaed file ##################*/
void gsim_close_unsaved(void)
{
	GtkWidget *dialog;
	
	GString *str;
	str=g_string_new("");
	g_string_append_printf(str,_("The file '%s' is not saved.\n Do you want to save it before closing ?"),filename);

   
   /* Create the widgets */
   
   	dialog = gtk_message_dialog_new(GTK_WINDOW(gsim_appwindow),GTK_DIALOG_DESTROY_WITH_PARENT,GTK_MESSAGE_QUESTION,
                                               GTK_BUTTONS_NONE,str->str);
	gtk_dialog_add_buttons(GTK_DIALOG(dialog),GTK_STOCK_CANCEL,GTK_RESPONSE_NONE,GTK_STOCK_NO,GTK_RESPONSE_NO,
												GTK_STOCK_SAVE,GTK_RESPONSE_YES,NULL);
                                       
	g_string_free(str,TRUE);

   /*decide what to do*/
   gint response;
   response=gtk_dialog_run(GTK_DIALOG(dialog));
   
   if(response==GTK_RESPONSE_YES)
	{
		if_close_file=1;
		if_file_processing=1;
		gsim_save_file();
		close_file();
	}
	if(response==GTK_RESPONSE_NO)
		close_file();
	
   gtk_widget_destroy(dialog);
}
